<div class="admin_form_row">
  <div>
    <label>Anexos</label>
    <div class="content">

        [?php echo $form['anexo']->renderHiddenFields() ?]

        <div class="addon_content">
        [?php foreach($form['anexo'] as $key => $detalle): ?]
          [?php if ($detalle->isHidden()) continue; ?]
          [?php include_partial('<?php echo $this->getModuleName() ?>/anexo_detalle', array('detalle' => $detalle)) ?]
        [?php endforeach ?]
        </div>
      <br />
      <ul class="admin_actions">
        <li class="admin_action_new"><a href="" id="addOn">Agregar anexo</a></li>
      </ul>
    </div>
  </div>  
</div>

<script type="text/javascript">

  $(function() {
    var index = $('.addon_content div.addon_detail_content').length;
    
    $('#addOn').click(function() {
      $.ajax({
        url: '[?php echo url_for('<?php echo $this->getModuleName()?>/addOn', array())?]',
        data: { index: index, anexo_id: [?php echo $form->getObject()->getAnexoId() == null ? 0 : $form->getObject()->getAnexoId() ?]},
        type: 'POST',
        async: false,
        success: function(data) {
          $('.addon_content').append(data);
          index = index + 1;
        }
      });

      return false;
    });
  });

</script>
